from typing import Any, Dict, Generator

import pydash
import pytest

from tests.ops.integration_tests.saas.connector_runner import (
    ConnectorRunner,
    generate_random_email,
)
from tests.ops.test_helpers.vault_client import get_secrets

secrets = get_secrets("{{ connector_id }}")


@pytest.fixture(scope="session")
def {{ connector_id }}_secrets(saas_config) -> Dict[str, Any]:
    return {
        "domain": pydash.get(saas_config, "{{ connector_id }}.domain")
        or secrets["domain"]
        # add the rest of your secrets here
    }


@pytest.fixture(scope="session")
def {{ connector_id }}_identity_email(saas_config) -> str:
    return (
        pydash.get(saas_config, "{{ connector_id }}.identity_email") or secrets["identity_email"]
    )


@pytest.fixture
def {{ connector_id }}_erasure_identity_email() -> str:
    return generate_random_email()


@pytest.fixture
def {{ connector_id }}_external_references() -> Dict[str, Any]:
    return {}


@pytest.fixture
def {{ connector_id }}_erasure_external_references() -> Dict[str, Any]:
    return {}


@pytest.fixture
def {{ connector_id }}_erasure_data(
    {{ connector_id }}_erasure_identity_email: str,
) -> Generator:
    # create the data needed for erasure tests here
    yield {}


@pytest.fixture
def {{ connector_id }}_runner(
    db,
    cache,
    {{ connector_id }}_secrets,
    {{ connector_id }}_external_references,
    {{ connector_id }}_erasure_external_references,
) -> ConnectorRunner:
    return ConnectorRunner(
        db,
        cache,
        "{{ connector_id }}",
        {{ connector_id }}_secrets,
        external_references={{ connector_id }}_external_references,
        erasure_external_references={{ connector_id }}_erasure_external_references,
    )
